package com.mycat.tencent.entity.request;


import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import com.alipay.api.internal.util.StringUtils;
import com.mycat.exception.PaymentException;

/**
 * 微信APP退款参数
 * @author roger.
 * @email luojie@yzworld.cn
 * @date 2016/9/9
 */
public class WxAppRefundParams implements Serializable {
	private static final long serialVersionUID = 63342709724560840L;
	// 应用ID  是
    private String appid;
    // 商户号  是
    private String mch_id;
    // 设备号  否
    private String device_info;
    // 随机字符串   是
    private String nonce_str;
    // 签名  是
    private String sign;
    // 微信订单号    商户订单号   二选一
    private String transaction_id;
    private String out_trade_no;
    // 商户退款单号   是
    private String out_refund_no;
    // 总金额   是
    private Integer total_fee;
    // 退款金额  是
    private Integer refund_fee;
    // 货币种类  否
    private String refund_fee_type;
    // 操作员  默认为商户号   是
    private String op_user_id;

    public Map<String,Object> toMap() throws Exception{
        Map<String,Object> map = new HashMap<>();
        if(StringUtils.isEmpty(this.getAppid())){
            throw new PaymentException("应用ID不能为空");
        }
        map.put("appid",this.getAppid());
        if(StringUtils.isEmpty(this.getMch_id())){
            throw new PaymentException("商户号不能为空");
        }
        map.put("mch_id",this.getMch_id());
        if(!StringUtils.isEmpty(this.getDevice_info())){
            map.put("device_info",this.getDevice_info());
        }
        if(StringUtils.isEmpty(this.getNonce_str())){
            throw new PaymentException("随机字符串不能为空");
        }
        map.put("nonce_str",this.getNonce_str());
        if(StringUtils.isEmpty(this.getOp_user_id())){
            throw new PaymentException("操作员不能为空");
        }
        map.put("op_user_id",this.getOp_user_id());

        if(StringUtils.isEmpty(this.getOut_refund_no())){
            throw new PaymentException("退款订单号不能为空");
        }
        map.put("out_refund_no",this.getOut_refund_no());

        if(StringUtils.isEmpty(this.getOut_trade_no()) && StringUtils.isEmpty(this.getTransaction_id())){
            throw new PaymentException("微信订单号、商户订单号不能都为空");
        }
        if(!StringUtils.isEmpty(this.getTransaction_id())){
            map.put("transaction_id",this.getTransaction_id());
        }
        if(!StringUtils.isEmpty(this.getOut_trade_no())){
            map.put("out_trade_no",this.getOut_trade_no());
        }
        if(!StringUtils.isEmpty(this.getTransaction_id())){
            map.put("transaction_id",this.getTransaction_id());
        }
        if(null == this.getTotal_fee()){
            throw new PaymentException("总金额不能为空");
        }
        map.put("total_fee",this.getTotal_fee());
        if(null == this.getRefund_fee()){
            throw new PaymentException("退款金额不能为空");
        }
        map.put("refund_fee",this.getRefund_fee());

        return map;
    }

    public String getAppid() {
        return appid;
    }

    public void setAppid(String appid) {
        this.appid = appid;
    }

    public String getMch_id() {
        return mch_id;
    }

    public void setMch_id(String mch_id) {
        this.mch_id = mch_id;
    }

    public String getDevice_info() {
        return device_info;
    }

    public void setDevice_info(String device_info) {
        this.device_info = device_info;
    }

    public String getNonce_str() {
        return nonce_str;
    }

    public void setNonce_str(String nonce_str) {
        this.nonce_str = nonce_str;
    }

    public String getSign() {
        return sign;
    }

    public void setSign(String sign) {
        this.sign = sign;
    }

    public String getTransaction_id() {
        return transaction_id;
    }

    public void setTransaction_id(String transaction_id) {
        this.transaction_id = transaction_id;
    }

    public String getOut_trade_no() {
        return out_trade_no;
    }

    public void setOut_trade_no(String out_trade_no) {
        this.out_trade_no = out_trade_no;
    }

    public String getOut_refund_no() {
        return out_refund_no;
    }

    public void setOut_refund_no(String out_refund_no) {
        this.out_refund_no = out_refund_no;
    }

    public Integer getTotal_fee() {
        return total_fee;
    }

    public void setTotal_fee(Integer total_fee) {
        this.total_fee = total_fee;
    }

    public Integer getRefund_fee() {
        return refund_fee;
    }

    public void setRefund_fee(Integer refund_fee) {
        this.refund_fee = refund_fee;
    }

    public String getRefund_fee_type() {
        return refund_fee_type;
    }

    public void setRefund_fee_type(String refund_fee_type) {
        this.refund_fee_type = refund_fee_type;
    }

    public String getOp_user_id() {
        return op_user_id;
    }

    public void setOp_user_id(String op_user_id) {
        this.op_user_id = op_user_id;
    }
}
